package com.daocao.hua.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.daocao.hua.R;
import com.daocao.hua.adapter.base.ItemAdapter;
import com.daocao.hua.model.PrizeIndexModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MainHomeOrderAdapter extends ItemAdapter<PrizeIndexModel.DataBean.RewardListBean, MainHomeOrderAdapter.DefaultHolder> {


    public MainHomeOrderAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_main_invite_order, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        PrizeIndexModel.DataBean.RewardListBean item = getItem(position);
        holder.txtId.setText(item.real_name);
        holder.txtName.setText("￥" + item.total_reward);
        if (position < 3) {
            holder.txtOrder.setVisibility(View.GONE);
            holder.imgOrder.setVisibility(View.VISIBLE);
            holder.txtId.setTextColor(0xff3F0600);
            switch (position){
                case 0:
                    holder.imgOrder.setImageResource(R.mipmap.img_main_prize_one);
                    break;
                case 1:
                    holder.imgOrder.setImageResource(R.mipmap.img_main_prize_two);
                    break;
                case 2:
                    holder.imgOrder.setImageResource(R.mipmap.img_main_prize_three);
                    break;
            }

        } else {
            holder.txtId.setTextColor(0x993F0600);
            holder.imgOrder.setVisibility(View.GONE);
            holder.txtOrder.setVisibility(View.VISIBLE);
            holder.txtOrder.setText("第" + item.ranking + "名");
        }


    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_order)
        ImageView imgOrder;
        @BindView(R.id.txt_order)
        TextView txtOrder;
        @BindView(R.id.txt_id)
        TextView txtId;
        @BindView(R.id.txt_name)
        TextView txtName;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
